const dbm = require('../config/dbModels');
const { verifyJWT,decodeJWTId } = require('../core/jwt');
const {aseDecode}=require('../core/crypto')
class UserDao {
 
    static async rUser(id) {
        return await dbm.User.findOne({
            where: {
                id
            },
            attributes:['qualification']
        })
    }

    static async dUser(ctx) {
        //这里不是删除,而是封禁账号
        let req = ctx.request.query
        let userId=req.id
        return await dbm.User.update(
            {status:req.status},
            {
                where: {
                    id:  userId
                }
            }
        )
    }

    static async uUser(ctx) {
        let req = ctx.request.body
        let userId=decodeJWTId(ctx)
        return await dbm.User.update(
            { ...req},
            {
                where: {
                    id:  userId
                }
            }
        )
    }

    static async getAllUser({ currentPage = 1,limit = 10}) {
        //offset偏移量
        //limit每页的条数
       let offset = (currentPage - 1) * limit;
       return await dbm.User.findAndCountAll({ limit:parseInt(limit), offset:parseInt(offset),raw:true,attributes: { exclude: ['password'] }})
   }
}
module.exports = UserDao
